$(function () {
    init_data();
    /**大资源导入配置**/
    $.getJSON(ctx+"bigEpExport/getlimitBigRecords",{},function (r) {
        var recodsArray = new Set();
        $.each(r,function (index,value) {
            recodsArray.add(value.epBatch);
        });
        $( "#bigempexportbatch" ).autocomplete({
            source: Array.from(recodsArray),
            select: function( event, ui ) {
                $("#bigempexportbatch").val(ui.item.label);
                $JuXue.refreshTable("bigEmpIpTable");
            }
        });
    });
    /**大资源导出配置**/
    $.getJSON(ctx+"bigScreen/exportRecordName",{},function (r) {
        var recodsArray = new Set();
        $.each(r,function (index,value) {
            recodsArray.add(value.cIpIname);
        });
        $( "#export-pici" ).autocomplete({
            source: Array.from(recodsArray),
            select: function( event, ui ) {
                $("#export-pici").val(ui.item.label);
                $JuXue.refreshTable("bigEmpIpTable");
            }
        });
    });


    $("#Screen-daterange span").html(moment().subtract("days",29).format("YYYY-MM-DD")+" - "+moment().format("YYYY-MM-DD"));

    $('#Screen-daterange').daterangepicker({
        timePicker: true, //显示时间
        timePicker24Hour: true, //时间制
        timePickerSeconds: true, //时间显示到秒
        startDate: moment().hours(0).minutes(0).seconds(0), //设置开始日期
        endDate: moment(new Date()), //设置结束器日期
        maxDate: moment(new Date()), //设置最大日期
        "opens": "center",
        ranges: {
            '今天': [moment(), moment()],'昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
            '上周': [moment().subtract(6, 'days'), moment()],
            '前30天': [moment().subtract(29, 'days'), moment()],
            '本月': [moment().startOf('month'), moment().endOf('month')],
            '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        },
        showWeekNumbers: true,
        locale: {
            format: "YYYY-MM-DD HH:mm:ss", //设置显示格式
            applyLabel: '确定', //确定按钮文本
            cancelLabel: '取消', //取消按钮文本
            customRangeLabel: '自定义',
            daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
            monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
                '七月', '八月', '九月', '十月', '十一月', '十二月'
            ],
            firstDay: 1
        },
    }).on('apply.daterangepicker', function(ev, picker) {
        var starttime = picker.startDate.format('YYYY-MM-DD');
        var endtime = picker.endDate.format('YYYY-MM-DD');
        $("#Screen-daterange span").html(starttime+" - "+endtime);
        $("#screestarttime").val(starttime)
        $("#screeendtime").val(endtime);
        $JuXue.refreshTable("bigEmpIpTable");
    });

    $('#bigempexportbatch').live('input propertychange', function() {
        $JuXue.refreshTable("bigEmpIpTable");
    });
    $('#export_drector').live('input propertychange', function() {
        $JuXue.refreshTable("bigEmpIpTable");
    });

    $('#export-pici').live('input propertychange', function() {
        $JuXue.refreshTable("bigEmpIpTable");
    });

})

/**初始化数据**/
function init_data(){
    var settings = {
        pageSize: 15,
        url: ctx + "bigScreen/exportRecord",
        queryParams: function(params) {
            return {
                pageSize: params.limit,
                pageNum: params.offset / params.limit + 1,
                cIpIname:$("#export-pici").val(),
                cIpEname:$("#bigempexportbatch").val(),
                cIpDirector : $("#export_drector").val(),
                starttime: $("#screestarttime").val(),
                endtime :$("#screeendtime").val(),
                cIpProject :$("#custScreenyixinput").val(),
                cIpStatus:$("#custScreenoverInput").val(),
            };
        },
        columns: [{
            field: 'cIpTime',
            class:'text-center',
            title: '导出时间',
            formatter:function (value, row, index) {
                return value.substring(0,10);
            }
        }, {
            field: 'cIpIname',
            title: '导出批次',
            class:'text-center',
            formatter:function (value, row, index) {
                return "<a href='javascript:void(0)' onclick='viewIpRecoredDetail(this)' data-click='"+row.cIpId+"'>"+value+"</a>";
            }
        },{
            field: 'cIpNum',
            class:'text-center',
            title: '导入数量'
        },{
            field: 'cIpUserfo',
            class:'text-center',
            title: '导出用途'
        }, {
            field: 'cIpOption',
            class:'text-center',
            title: '操作人'
        }, {
            field: 'cIpStatus',
            class:'text-center',
            title: '导出操作',
            formatter:function (value, row, index) {
                var cpid = row.cIpId;
                if (value == 0){
                    return " <a href=\"javascript:void(0);\" onclick='exportCurentBatchCus(this)' data-click='"+cpid+"' class=\"email-btn\" title='导出' ><i class=\"fa fa-download m-r-10\"></i></a>\n" +
                        "<a href=\"javascript:void(0);\" onclick='ignoreCurentBatchCus(this)' data-click='"+cpid+"' class=\"email-btn\" title='忽略' ><i class=\"fa fa-trash-o\"></i></a>";
                }else if (value == 1){
                    return "已确认";
                }
                return " <a href=\"javascript:void(0);\" onclick='recoverCurentBatchCus(this)'data-click='"+cpid+"' class=\"email-btn\" title='恢复' ><i class=\"fa fa-retweet m-r-10\"></i></a>\n";
            }
        }]
    };
    $JuXue.initTable('bigEmpIpTable', settings);
}

